<template>
  <x-main>
    <view class="order">
      <x-search :statusOption="BILL.STATUS" @search="onSearch"></x-search>
      <view style="padding-top: 200rpx">
        <x-empty :show="$emptyArray(records)"></x-empty>
        <template v-for="(data, index) in records" >
          <x-item :data="data"></x-item>
        </template>
      </view>
    </view>
  </x-main>
</template>

<script setup>
import {reactive} from "vue";
import XSearch from '@/components/logic/search'
import XItem from '@/components/logic/bill/item'
import billStore from '@/stores/modules/bill';
import {onLoad, onReachBottom, onShow} from "@dcloudio/uni-app";
import {storeToRefs} from "pinia";
import {Helper} from "core";

const BillStore = billStore();
const {pageNo, pageSize, total, condition, records} = storeToRefs(BillStore);
onShow(() => {
  BillStore.getList(1, pageSize.value, condition.value);
})

const onSearch = (searchData) => {
  if(! Helper.empty(searchData.keyword)) {
    searchData.userPhone = searchData.keyword;

  }

  if(! Helper.empty(searchData.status)) {
    searchData.billState = [searchData.status];

  }
  delete searchData.status;
  delete searchData.keyword;
  condition.value = searchData;
  BillStore.getList(1, pageSize.value, condition.value);
}

onReachBottom(() => {
  BillStore.getList(pageNo.value + 1, pageSize.value, condition.value);
})

</script>

<style scoped lang="less">
.order {

}
</style>
